<template>
  <div class='container'>
    <el-dialog
      :visible.sync="dialogFormVisible"
      width="26%"
      :title="titleInfo.text+titleInfo.pageTitle"
      v-if="dialogFormVisible">
      <el-form
        :model="formBase"
        :rules="ruleInline">
        <el-form-item label="学科名称" label-width="80px" prop="subjectName">
          <el-input v-model="formBase.subjectName" placeholder="请输入学科名称"></el-input>
        </el-form-item>
        <el-form-item label="是否显示" label-width="80px">
            <!-- v-model="isFrontDisplay" -->
          <el-switch
            v-model="value"
            active-color="#13ce66"
            inactive-color="#ff4949"
            active-value="1"
            inactive-value="0">
          </el-switch>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormH">取 消</el-button>
        <el-button type="primary" @click="createData">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { update, add } from '@/api/hmmm/subjects.js'
export default {
  props: {
    titleInfo: {
      type: Object,
      required: true
    },
    formBase: {
      type: Object,
      required: true
    },
    parameter: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      dialogFormVisible: false,
      value: true,
      // 表单验证
      ruleInline: {
        subjectName: [
          {
            required: true, message: '*不能为空', trigger: 'blur'
          }
        ]
      }
    }
  },
  methods: {
    // 提示框标签显示
    dialogFormV () {
      this.dialogFormVisible = true
    },
    // 提示框标签隐藏
    dialogFormH () {
      this.dialogFormVisible = false
    },
    // 提交
    async createData () {
      this.dialogFormV()
      // const data = {
      //   ...this.formBase
      // }
      if (this.formBase.id) {
        this.formBase.isFrontDisplay = this.value
        console.log(this.value)
        // 修改
        await update(this.formBase).then(() => {
          this.dialogFormH()
          this.$emit('newDates', this.formBase)
          this.$message.success('操作成功')
        })
      } else {
        // 增加
        console.log(this.formBase)
        this.formBase.isFrontDisplay = this.value
        await add(this.formBase).then(() => {
          this.dialogFormH()
          this.$emit('newDates', this.formBase)
          this.$message.success('操作成功')
          this.parameter.page = 1
        })
      }
    }
  }
}
</script>

<style scoped lang='scss'></style>
